/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.telsoft.security.data;

import com.telsoft.security.business.SEC_BU_Group;
import com.telsoft.security.business.SEC_BU_USER_GROUP;
import com.telsoft.security.business.SEC_BU_User;
import com.telsoft.security.entity.SEC_ETT_Group;
import com.telsoft.security.entity.SEC_ETT_User;
import com.telsoft.security.entity.SEC_ETT_UserGroup;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author nguyenthang
 */
public class SEC_DATA_UG {
    Connection connect = null;
    public SEC_ETT_UserGroup getUGByUserID(int userID){
        SEC_ETT_UserGroup ug = new SEC_ETT_UserGroup();
        try {
            SEC_ETT_Group gr1 = SEC_BU_USER_GROUP.getGroupByUserID(userID);
            SEC_ETT_Group gr2 = SEC_BU_Group.getGroupByID(gr1.getGROUP_ID());
            SEC_ETT_User us = SEC_BU_User.getUserByID(userID);
            ug.setUSER_ID(us.getUSER_ID());
            ug.setUSER_NAME(us.getUSER_NAME());
            ug.setFULL_NAME(us.getFULL_NAME());
            ug.setUSER_STATUS(us.getSTATUS());
            ug.setUSER_EMAIL(us.getEMAIL());
            ug.setGROUP_NAME(gr2.getGROUP_NAME());
            ug.setUSER_PASSWORD(us.getPASSWORD());
        } catch (Exception ex){
            ex.toString();
        }
        return ug;
    }
    
    public List<SEC_ETT_UserGroup> getAllUG(){
        List<SEC_ETT_UserGroup> listUg = new ArrayList<SEC_ETT_UserGroup>();
        List<SEC_ETT_User> listUser = SEC_BU_User.getAllUser();
        for (int i =0; i<listUser.size(); i++){
            listUg.add(getUGByUserID(listUser.get(i).getUSER_ID()));
        }
        return listUg;
    }
}
